﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Argos.Activities.MessageDelivery;
using System.Xml;
using Argos.Scheduling;
using Argos.Data.Model;
using Argos.Workflows;
using Argos.Activities.Tests;

namespace Argos.Core.Tests
{
	[TestClass]
	public class MessagingTests
	{

		#region public TestContext TestContext { get; set; }

		private TestContext testContextInstance;

		/// <summary>
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///</summary>
		public TestContext TestContext
		{
			get
			{
				return testContextInstance;
			}
			set
			{
				testContextInstance = value;
			}
		}

		#endregion



		#region Test: public void SerializeMessage01()

		[global::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()]
		[global::Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Creates an 'AlertMessage' object instance and serializes it.")]
		public void SerializeMessage01()
		{
			AlertMessage msg = new AlertMessage();
			msg.Body = "Body";
			msg.BodyContentType = "text/notsoplain";
			msg.RecipientAddress = "address";
			msg.RecipientName = "name";
			msg.Subject = "subject";

			string xml = msg.ToXmlString();
			Assert.IsNotNull(xml);

			XmlDocument doc = new XmlDocument();
			doc.LoadXml(xml);

			Assert.AreEqual<string>("http://develore.com/schemas/2008/06/argos/messagedelivery/alertmessage.xsd", doc.DocumentElement.NamespaceURI);
		}

		#endregion

		#region Test: public void SerializeMessage02()

		[global::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()]
		[global::Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Deserializes a message from resources.")]
		public void SerializeMessage02()
		{
			AlertMessage msg = AlertMessage.FromXmlString(Properties.Resources.AlertMessage01);
			Assert.AreEqual<string>("Body", msg.Body);
			Assert.AreEqual<string>("text/notsoplain", msg.BodyContentType);
			Assert.AreEqual<string>("address", msg.RecipientAddress);
			Assert.AreEqual<string>("name", msg.RecipientName);
			Assert.AreEqual<string>("subject", msg.Subject);
		}

		#endregion

		#region Test: public void SerializeMessage03()

		[global::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()]
		[global::Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute(" ")]
		public void SerializeMessage03()
		{
			AlertMessage msg1 = new AlertMessage();
			msg1.RawData.Add(Schedule.OfficeHours);

			AlertMessage msg2 = AlertMessage.FromXmlString(msg1.ToXmlString());
			Assert.AreEqual<int>(1, msg2.RawData.Count);
			Assert.AreEqual(Schedule.OfficeHours, msg2.RawData[0]);
		}

		#endregion

		#region Test: public void SerializeMessage04()

		[global::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()]
		[global::Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute(" ")]
		public void SerializeMessage04()
		{
			AlertMessage msg1 = new AlertMessage();
			msg1.Target = new Target();
			msg1.Target.Name = "New Target";
			msg1.Target.MonitoringWorkflowType = typeof(TargetFailureMonitoringWorkflow);
			msg1.Target.Test.ActivityType = typeof(PingTestActivity);
			msg1.Target.Test.ActivityProperties["Host"] = "localhost";

			AlertMessage msg2 = AlertMessage.FromXmlString(msg1.ToXmlString());

			Assert.AreEqual<Target>(msg1.Target, msg2.Target);
		}

		#endregion

		#region Test: public void SerializeMessage05()

		[global::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()]
		[global::Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute(" ")]
		public void SerializeMessage05()
		{
			AlertMessage msg1 = new AlertMessage();
			msg1.AlertType = AlertTypes.Failure;

			AlertMessage msg2 = AlertMessage.FromXmlString(msg1.ToXmlString());
			Assert.AreEqual<AlertTypes>(AlertTypes.Failure, msg2.AlertType);
		}

		#endregion

		#region Test: public void SerializeMessage06()

		[global::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()]
		[global::Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute(" ")]
		public void SerializeMessage06()
		{
			AlertMessage msg1 = new AlertMessage();
			AlertMessage msg2 = AlertMessage.FromXmlString(msg1.ToXmlString());

			Assert.AreEqual<DateTime>(msg1.CreatedDate, msg2.CreatedDate);
		}

		#endregion
		
	}
}
